#!/usr/bin/env bash

# Filename     :	docker-install-ubuntu22.sh
# Last modified:	2024-05-11 12:12
# Version      :
# Author       : jack.zang
# Email        : jack.zang@aishangwei.net
# Description  :
# 使用方法：source <(curl -sL https://gitee.com/jack_zang/public-scripts/raw/master/shell/docker/docker-compose_install.sh)
# ******************************************************

## 检查操作系统类型，加载 /etc/os-release 之后，会得到一个 $ID 变量
if [ -f /etc/os-release ]; then
    . /etc/os-release
    OS=$ID
else
    echo "无法确定操作系统类型。"
    exit 1
fi

## 根据操作系统类型安装 docker-compose
case $OS in
    ubuntu)
        install_docker-compose_ubuntu
        ;;
    centos)
        echo "待补充"
        ;;
    *)
        echo "不支持的操作系统类型：$OS"
        exit 1
        ;;
esac

## 查看 docker-compose 版本
docker-compose version
echo "docker-compose 安装完成"
## 查看可以安装的版本
#apt-cache madison docker-compose


install_docker-compose() {
    echo "--- 安装 docker-compose"
    curl -SL https://github.com/docker/compose/releases/download/v2.29.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
    if [ $? -eq 0 ]; then
        curl -SL https://files.aishangwei.net/files/docker/docker-compose
    fi
}


install_docker-compose_ubuntu() {
  sudo apt install apt-transport-https ca-certificates -y
  echo "---------- 安装 docker-compose"
  curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-ce-keyrings.gpg
  echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-ce-keyrings.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker-ce.list
  sudo apt-get update
  sudo apt install -y docker-compose
}




















